<?php

namespace app\common\model;

use think\Model;
use think\model\concern\SoftDelete;

class Video extends Model
{
    use SoftDelete;

    public function videoList()
    {
        return $this->hasMany('VideoList', 'video_id', 'id');
    }

    public function add($data)
    {
        $validate = new \app\common\validate\Video();
        if (!$validate->scene('add')->check($data)) {
            return $validate->getError();
        }
        $result = $this->allowField(true)->save($data);
        if ($result) {
            return 1;
        }else {
            return '添加失败！';
        }
    }

    public function edit($data)
    {
        $validate = new \app\common\validate\Video();
        if (!$validate->scene('edit')->check($data)) {
            return $validate->getError();
        }
        $videoInfo = $this->find($data['id']);
        $videoInfo->title = $data['title'];
        $result = $videoInfo->save();
        if ($result) {
            return 1;
        }else {
            return '编辑失败！';
        }
    }
}
